<template>
  <div id="couponTop">
    <h1 class="con-right-title">
      <i class="fa fa-reply" @click="cancel"></i>
      优惠券管理/查看明细
    </h1>
    <div class="search-box">
      <el-form ref="ruleForm" :inline="true" :model="formInline">
        <!-- 输入搜索部分 -->
        <el-form-item label="大鹏号" prop="dpAccount">
          <el-input
            v-model="formInline.dpAccount"
            placeholder="请输入大鹏号  "
            size="small"
            class="numberInput"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="订单号" prop="orderId">
          <el-input
            v-model="formInline.orderId"
            placeholder="请输入订单号"
            size="small"
            class="numberInput"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="使用状态" prop="status">
          <el-select
            class="short-input"
            v-model="formInline.status"
            placeholder="请选择使用状态"
            clearable
          >
            <el-option
              v-for="item in statusList"
              :key="item.dictLabel"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发放时间" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="使用时间" prop="useTime">
          <el-date-picker
            v-model="formInline.useTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getDpNum } from '@/api/system/user'
export default {
  name: 'couponTop',
  msg: '优惠券管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          dpAccount: '', // 大鹏号
          orderId: '', // 订单号
          status: '', // 使用状态
          createTime: [], // 发放时间
          grantStartTime: '', // 发放的开始时间
          grantEndTime: '', // 发放的结束时间
          useTime: [], // 使用时间
          useStartTime: '', // 使用开始时间
          useEndTime: '' // 使用结束时间
        }
      }
    }
  },
  data() {
    return {
      statusList: [{ dictLabel: '全部', dictValue: '' }], //发放类型
      // 修改人列表
      operatorsList: [{ nickname: '全部', userId: '' }]
    }
  },
  watch: {
    'formInline.useTime': {
      //使用时间
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.useStartTime = newVal[0]
          this.formInline.useEndTime = newVal[1]
        } else {
          this.formInline.useStartTime = ''
          this.formInline.useEndTime = ''
        }
      },
      deep: true
    },
    'formInline.createTime': {
      //发放时间
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.grantStartTime = newVal[0]
          this.formInline.grantEndTime = newVal[1]
        } else {
          this.formInline.grantStartTime = ''
          this.formInline.grantEndTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    async getStatusList() {
      /*优惠券发放类型*/
      await sysNormalDisable('grant_types', 'grant_types')
      /* 使用状态 */
      let data = await sysNormalDisable('coupon_status', 'coupon_status')
      this.statusList = this.statusList.concat(data)
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 取消 */
    cancel() {
      this.$router.go(-1)
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>

<style lang="less">
#couponTop {
  .short-input {
    .el-input__inner {
      width: 90px !important;
    }
  }
}
</style>
